package vn.appsmobi.adapter;

import java.util.ArrayList;

import vn.appsmobi.R;
import vn.appsmobi.model.AppCommentInfo;
import vn.appsmobi.ui.AppCommentsItem;
import vn.appsmobi.ui.ExpandableTextView;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class AppCommentsAdapter extends BaseDataAdapter<AppCommentInfo>
{
  private String mCurrentVersion = "";
  private ExpandableTextView.OnExpandListener mExpandListener = new ExpandableTextView.OnExpandListener()
  {
    public void onExpand(ExpandableTextView paramAnonymousExpandableTextView)
    {
      AppCommentInfo localAppCommentInfo = (AppCommentInfo)paramAnonymousExpandableTextView.getTag();
      if (localAppCommentInfo != null)
        AppCommentsAdapter.this.mExpandedItemList.add(localAppCommentInfo);
    }
  };
  private ArrayList<AppCommentInfo> mExpandedItemList = new ArrayList<AppCommentInfo>();
  private LayoutInflater mInflater = null;


  public AppCommentsAdapter(Context context)
  {
    super(context);
    this.mInflater = LayoutInflater.from(context);
  }

  public void bindView(View paramView, int paramInt, AppCommentInfo paramAppCommentInfo)
  {
    AppCommentsItem localAppCommentsItem = (AppCommentsItem)paramView;
    ExpandableTextView content = localAppCommentsItem.getCommentContentView();
    content.setTag(paramAppCommentInfo);
    content.expand(this.mExpandedItemList.contains(paramAppCommentInfo));
    localAppCommentsItem.setCurrentVersion(this.mCurrentVersion);
    localAppCommentsItem.rebind(paramAppCommentInfo);
  }

  public View newView(Context paramContext, AppCommentInfo commentInfo, ViewGroup parent)
  {
    AppCommentsItem commentItem = (AppCommentsItem)this.mInflater.inflate(R.layout.app_comments_list_item, parent, false);
    commentItem.bind(commentInfo);
    commentItem.getCommentContentView().setExpandListener(this.mExpandListener);
    return commentItem;
  }

  public void setCurrentVersion(String paramString)
  {
    this.mCurrentVersion = paramString;
  }
}
